// vars/buildJavaApp.groovy

def call(Map config) {
    // 默认配置
    def defaultConfig = [
        branch: 'master',
        buildTool: 'mvn clean install'
    ]
    // 合并传入的配置和默认配置
    config = defaultConfig + config

    // 使用pipeline的语法块
    pipeline {
        agent any
        stages {
            stage('Checkout') {
                steps {
                    git branch: config.branch, url: config.repoUrl
                }
            }
            stage('Build') {
                tools {
                    jdk 'JDK1.8_8U161'
                    maven 'maven_3.9.11'
                }
                steps {
                    sh config.buildTool
                }
            }
            stage('Archive') {
                steps {
                    archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
                }
            }
        }
    }
}